<template>
  <div>
    <a-form-model 
    :model="form" 
    :label-col="labelCol" 
    :wrapper-col="wrapperCol">
      <a-form-model-item label="姓名">
        <a-input v-model="form.name" />
      </a-form-model-item>

      <a-form-model-item label="密码">
        <a-input v-model="form.password" />
      </a-form-model-item>

      <a-form-model-item :wrapper-col="{ span: 14, offset: 4 }">
        <a-button type="primary" @click="onSubmit">
          登录
        </a-button>
      </a-form-model-item>
    </a-form-model>
  </div>
</template>
<script>
export default {
  data() {
    return {
      form: {
        name: "",
        password: "",
      },
    };
  },
  methods: {
    // 登录
    onSubmit() {
      // 请求接口
      this.$axios
        .post("http://ceshi5.dishait.cn/admin/login", {
          username: this.form.name,
          password: this.form.password,
        })
        .then((res) => {
          // console.log(res);
          localStorage.token = res.data.data.token;
          // 登录成功后跳转到 首页
          this.$router.push({ path: "/main/home/shoplist" });
        })
        .catch(() => {
          alert("登录失败");
        });
    },
  },
};
</script>
